/**
 * yybtj管理初始化
 */
var Brank = {
    id: "BrankTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Brank.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '营业部名称', field: 'gSalesName', visible: true, align: 'center', valign: 'middle'},
            {title: '营业部代码', field: 'gSalesCode', visible: true, align: 'center', valign: 'middle'},
            {title: '上榜1天买入次数', field: 'gBcount1dc', visible: true, align: 'center', valign: 'middle'},
            {title: '平均涨幅', field: 'gAvgRate1dc', visible: true, align: 'center', valign: 'middle'},
            {title: '上涨概率(%)', field: 'gUpRate1dc', visible: true, align: 'center', valign: 'middle'},
            {title: '上榜2天买入次数', field: 'gBcount2dc', visible: true, align: 'center', valign: 'middle'},
            {title: '平均涨幅', field: 'gAvgRate2dc', visible: true, align: 'center', valign: 'middle'},
            {title: '上涨概率(%)', field: 'gUpRate2dc', visible: true, align: 'center', valign: 'middle'},
            {title: '上榜3天买入次数', field: 'gBcount3dc', visible: true, align: 'center', valign: 'middle'},
            {title: '平均涨幅', field: 'gAvgRate3dc', visible: true, align: 'center', valign: 'middle'},
            {title: '上涨概率(%)', field: 'gUpRate3dc', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
Brank.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Brank.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加yybtj
 */
Brank.openAddBrank = function () {
    var index = layer.open({
        type: 2,
        title: '添加yybtj',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/brank/brank_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看yybtj详情
 */
Brank.openBrankDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'yybtj详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/brank/brank_update/' + Brank.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除yybtj
 */
Brank.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/brank/delete", function (data) {
            Feng.success("删除成功!");
            Brank.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("brankId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询yybtj列表
 */
Brank.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    Brank.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Brank.initColumn();
    var table = new BSTable(Brank.id, "/brank/list", defaultColunms);
    table.setPaginationType("server");
    Brank.table = table.init();
});
